/**
 * 详情对话框
 */
var ContractSettingInfoDlg = {
    data: {
        price: "",
        price1: "",
        contractName: "",
        contractType: "",
        earnings:"",
        buyingTime: "",
        buyingVipTime: "",
        deliveryTime: "",
        deliveryVipTime: "",
        repertory: "",
        ordinal: "",
        standby1: "",
        standby2: "",
        standby3: "",
        standby4: "",
        standby5: "",
        createTime: "",
        updateTime: "",
        updateUser: "",
        createUser: "",
        version: ""
    }
};

layui.use(['form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;


    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/contractSetting/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    result.data.price=(result.data.price/100);
    result.data.price1=(result.data.price1/100);
    result.data.buyingTime=(result.data.buyingTime/60/60);
    result.data.buyingVipTime=(result.data.buyingVipTime/60/60);
    layui.$('select').attr('disabled',true);
    form.val('contractSettingForm', result.data);
    //校验
    form.verify({
        // 方式一
        // value：表单的值、item：表单的DOM对象
        operationCount: function(value, item){
            if(/^[+]{0,1}(\d+)$/) {
                return '填写数字必须为正整数！'
            }
        },

        // 方式二
        // 数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
        operationCount: [
            /^[+]{0,1}(\d+)$/,
            '填写数字必须为正整数！'
        ]
    });

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
       if (data.price>data.price1){
           Feng.error("初始价格不能大于结束价格")
           return ;
       }
        var ajax = new $ax(Feng.ctxPath + "/contractSetting/editItem", function (data) {
            if (data.code==200){
                Feng.success("更新成功！");
            }else {
                Feng.error("更新失败！" + data.message)
            }
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

});